package com.taskmanager;

import com.taskmanager.tasks.Task;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AddTaskActivity extends TaskManagerActivity {
   
	private EditText taskNameEditText;
	private Button addButton;
	private Button cancelButton;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setUpViews();
    }
    
	protected void addTask() {
		String taskName = taskNameEditText.getText().toString();
		Task t = new Task(taskName);
		getTaskManagerApplication().addTask(t);
		finish();
		
	}
	
	protected void cancel() {
	    	finish();
			
		}

	private void setUpViews() {
		// TODO Auto-generated method stub
		
		taskNameEditText = (EditText)findViewById(R.id.task_name);
		addButton = (Button)findViewById(R.id.add_button);
		cancelButton = (Button)findViewById(R.id.cancel_button);
		
		addButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addTask();
			}
		});
		
		cancelButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				cancel();
				
			}
		});
		
	}

	
}